package com.gzcstec.service;

import com.gzcstec.dao.HostDao;
import com.gzcstec.domain.Host;
import com.gzcstec.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 站点业务实现类
 */
@Service
public class HostServiceImpl implements HostService {

    @Autowired
    private HostDao hostDao;

    @Override
    public Host getById(String hostId) {
        if(StringUtils.isEmpty(hostId)) {
            return null;
        }
        return hostDao.getById(hostId);
    }

    @Override
    public Host getByState(String state) {
        if(StringUtils.isEmpty(state)) {
            return null;
        }
        return hostDao.getByState(state);
    }

    @Override
    public int addHost(Host host) {
        if(null == host) {
            return 0;
        }
        host.setHostId(UUIDUtils.getUUID());
        host.setState(UUIDUtils.getUUID());
        return hostDao.addHost(host);
    }

    @Override
    public List<Host> getList() {
        return hostDao.getList();
    }

    @Override
    public int updateHost(Host host) {
        if(null == host) {
            return 0;
        }
        return hostDao.updateHost(host);
    }

    @Override
    public int deleteHost(String hostId) {
        if(StringUtils.isEmpty(hostId)) {
            return 0;
        }
        return hostDao.deleteHost(hostId);
    }
}
